package com.sicheng.lc.周赛.分类.图论;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/8/28 20:25
 */
public class 边积分最高的节点 {
    //https://leetcode.cn/problems/node-with-highest-edge-score/
    public int edgeScore(int[] g) {
        int n = g.length;
        long[] score = new long[n];
        long max = 0;
        int t = n;
        for (int i = 0; i < g.length; i++) {
            score[g[i]] += i;
            if (score[g[i]] > max) {
                t = g[i];
                max = score[g[i]];
            } else if (score[g[i]] == max) {
                t = Math.min(t, g[i]);
            }
        }
        return t;
    }
}
